﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestWentongPlateNumber300
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            wentong = new Wentong300Cameral.Discriminate(this);
        }

        private Wentong300Cameral.Discriminate wentong = null;

        private void Form1_Load(object sender, EventArgs e)
        {

            
            wentong.DisCriminateStatus += Wentong_DisCriminateStatus;
            wentong.updateDeviceEvent += PlateNumber;
            wentong.errorEvent += PlateNumberErrorInfo;

            DevExpress.XtraBars.Docking.DockPanel a_panel = dockManager1.AddPanel(DevExpress.XtraBars.Docking.DockingStyle.Right);
            DevExpress.XtraBars.Docking.DockPanel b_panel = a_panel.AddPanel();

            a_panel.DockAsTab(a_panel);
            b_panel.Controls.Add(wentong);



        }

        private void PlateNumberErrorInfo(Int16 index, string err)
        {

            textBox2.Text = err;

        }

        private void PlateNumber(Int16 index, string strIP, uint nType)
        {
            this.Text = strIP;
        }
        private void Wentong_DisCriminateStatus(short index, string plateNumber, short dType, byte[] picPlateNumber, byte[] picCar)
        {
            textBox1.Text = plateNumber;
            pictureBox2.Image = System.Drawing.Image.FromStream(new MemoryStream(picPlateNumber));
            pictureBox3.Image = System.Drawing.Image.FromStream(new MemoryStream(picCar));

        }

        private void button1_Click(object sender, EventArgs e)
        {



            wentong.Ip = "192.168.110.51";
            wentong.DeviceIndex = 0;
            wentong.Connect();
            

        }

        private void button2_Click(object sender, EventArgs e)
        {
            wentong.StopVideo();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (wentong.IsConnect)
            {
                wentong.StartVideo();
            }
            else
            {
                MessageBox.Show("没有连接到设备");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            wentong.Disconnect();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            wentong.Close();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //先关闭 
            wentong.StopVideo();
            wentong.Disconnect();

            this.Text = "重新连接";
            button1_Click(null, null);

        }
    }
}
